exports.getMonth = getMonth;
exports.getMinute = getMinute;
exports.getCurrentDateTimeSec = getCurrentDateTimeSec;
exports.getCurrentDateTimeMil = getCurrentDateTimeMil;
exports.validateyMdHms = validateyMdHms;
exports.validateyMdHmsWithSymbol = validateyMdHmsWithSymbol;
exports.validateyMdWithSymbol = validateyMdWithSymbol;

Date.prototype.format = function(fmt) {
  var o = {
    'M+': this.getMonth() + 1, //月份
    'd+': this.getDate(), //日
    'h+': this.getHours(), //小时
    'm+': this.getMinutes(), //分
    's+': this.getSeconds(), //秒
    'q+': Math.floor((this.getMonth() + 3) / 3), //季度
    'S': this.getMilliseconds() //毫秒
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
  return fmt;
};

function validateDate(pattern, dateStr) {
  var fulYear = dateStr.substring(0, 4);
  var month = dateStr.substring(4, 6) - 1;
  var day = parseInt(dateStr.substring(6, 8));
  var hours = dateStr.substring(8, 10);
  var minutes = dateStr.substring(10, 12);
  var seconds = dateStr.substring(12, 14);
  var milliseconds = dateStr.substring(14, 17);
  var date = new Date();
  date.setMilliseconds(milliseconds);
  date.setSeconds(seconds);
  date.setMinutes(minutes);
  date.setHours(hours);
  date.setUTCDate(day);
  date.setUTCMonth(month);
  date.setFullYear(fulYear);
  return date.format(pattern) === dateStr ? true : false;
}

function getMonth() {
  return new Date().format('yyyyMMdd');
}

function getMinute() {
  return new Date().format('yyyyMMddhhmm');
}

function getCurrentDateTimeMil() {
  return new Date().format('yyyyMMddhhmmssS');
}

function getCurrentDateTimeSec() {
  return new Date().format('yyyyMMddhhmmss');
}

function validateyMdHms(dateStr) {
  return validateDate('yyyyMMdd', dateStr);
}

function validateyMdHmsWithSymbol(dateStr) {
  return validateDate('yyyy-MM-dd HH:mm:ss', dateStr);
}

function validateyMdWithSymbol(dateStr) {
  return validateDate('yyyy-MM-dd', dateStr);
}